// common.js
// 封装提示，默认icon为none
export const showT = (text) => {
  uni.showToast({
    title: text,
    icon: "none"
  })
}

// 封装axios请求code为0的情况
export const axiosError = (res) => {
  if (res.data.code == 0) {
    showT(res.data.msg); 
    uni.hideLoading();
    return 0;
  }
  return res; 
}

import axios from "axios";

// 检查Token有效性
export const checkToken = async()=>{
	// 取出localstorage中的token
	let token = uni.getStorageSync("token");
	if(token == ""){
		gotoAuthPage();
		return false;
	}
	
	let res = await uni.$http.post("/common/checkToken", {token: token});
	if(res.data.code == 0){
		gotoAuthPage();
		return false;
	}
	
	return true;
	
}

function gotoAuthPage(){
	uni.$showT("登录状态异常，即将跳转登录...");
	setTimeout(()=>{
		uni.navigateTo({
			url: "/pages/auth/auth"
		})
	}, 1500)
}